<?php
namespace App\Modules\Relationship\Models;


use App\Http\Services\CommonServices;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use App\Http\Model\Base;

class RelationshipTasksModel extends Base {

    protected $table = "rs_relationship_tasks";

    protected $fields = ['id', 'content', 'rule', 'upper_limit as upperLimit', 'intimacy',
        'button_content as buttonContent', 'button_url as buttonUrl',
        'img_url as imgUrl', 'type', 'code'];
    protected $tablePrefix = '';
    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
        $this->tablePrefix = env('DB_PREFIX');
    }

    // 获取某种用户关系的增长任务
    public function getTasks(int $type, $code = ''){
        $table = $this->tablePrefix . $this->table;
        $fields = implode(',', $this->fields);
        $sql = "SELECT {$fields} FROM {$table} WHERE type=? AND is_deleted = 0";

        $rows = DB::select($sql, array($type));
        return self::objToArray($rows);
    }

    // 获取某种用户关系的增长任务
    public function getOneTask(int $type, $code = ''){
        $con = array('type'=>$type,'code'=>$code, 'is_deleted'=>0);
        return $this->getOneByCondition($con, $this->fields);
    }
}

